import { defineConfig, loadEnv } from "vite"
import react from "@vitejs/plugin-react"
const baseConfig = {
  plugins: [react()],
  css: {
    modules: {
      localsConvention: "camelCaseOnly",
    },
  },
}

// https://vite.dev/config/
// @ts-expect-error 别报错球球了
export default defineConfig(({ command, mode }) => {
  // 代理选项，开发环境使用
  // 开发环境
  // console.log(mode, command)
  const env = loadEnv(mode, process.cwd() + "")
  if (command === "serve") {
    return {
      ...baseConfig,
      server: {
        proxy: {
          [env.VITE_APP_BASE_URL]: {
            target: env.VITE_APP_BASE_SERVICE,
            changeOrigin: true,
            rewrite: (path) =>
              path.replace(new RegExp("^" + env.VITE_APP_BASE_URL), ""),
          },
        },
      },
    }
  } else {
    return { ...baseConfig }
  }
})
